package win.zxshuo.www.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ApplicationContextProvider implements ApplicationContextAware {

    // Spring boot 实现多线程多实例（PS:该方法DAO层也还是单实例）

    private static ApplicationContext context;

    private ApplicationContextProvider(){}

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException{
        context = applicationContext;
    }


    public static <T> T getBean(String name,Class<T> tClass){
        return context.getBean(name,tClass);
    }
}
